package com.wf.chatManagement.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wf.apicommons.entity.chatManagement.ChatRecord;
import com.wf.apicommons.entity.chatManagement.FriendsRelationship;
import com.wf.apicommons.entity.chatManagement.GroupInfo;
import com.wf.apicommons.utils.CommonResult;
import com.wf.apicommons.utils.SnowflakeUtil;
import com.wf.chatManagement.service.local.ChatRelatedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;
import java.util.Scanner;

@RestController
@RequestMapping("/chatRelated")
public class ChatRelatedController {

    @Autowired
    @Qualifier("chatRelatedServiceImpl")
     private  ChatRelatedService  chatRelatedService;


    /**
     * 创建一条好友验证关系数据
     * @param friendsRelationship
     * @return
     */
    @PostMapping("/addFriend")
    public  CommonResult<String>  createFriendVerification(@RequestBody FriendsRelationship friendsRelationship){
        return chatRelatedService.createFriendVerification(friendsRelationship);
    }

    /**
     * 添加一条群聊信息
     * @param groupInfo
     * @return
     */
   @PostMapping("/addGroup")
   public  CommonResult<String> addGroupInfo(@RequestBody GroupInfo groupInfo){
        return chatRelatedService.addGroupInfo(groupInfo);
    }

    /**
     * 查询我的好友列表
     * @param param
     * @return
     */
    @PostMapping("/queryFriends")
    public CommonResult<Page<Map<String,Object>>> queryMyFriendsList(@RequestBody Map<String,Object> param){
        return chatRelatedService.queryMyFriendsList(param);
    }

    /**
     * 查询我的加入的群聊列表
     * @param param
     * @return
     */
    @PostMapping("/queryJoinGroup")
    public CommonResult<Page<Map<String,Object>>>  queryGroupChatListIJoined(@RequestBody  Map<String,Object> param){
        return chatRelatedService.queryGroupChatListIJoined(param);
    }

    /**
     * 查询我创建的群聊列表
     * @param param
     * @return
     */
    @PostMapping("/queryCreateGroup")
    public CommonResult<Page<Map<String,Object>>>  queryMyCreateGroupChatList (@RequestBody  Map<String,Object> param){
        return chatRelatedService.queryMyCreateGroupChatList(param);
    }

    /**
     * 查询会话列表
     * @param param
     * @return
     */
    @PostMapping("/querySessionList")
    public  CommonResult<Page<Map<String,Object>>> querySessionList(@RequestBody  Map<String,Object> param){
        return chatRelatedService.querySessionList(param);
    }


    /**
     * 查询聊天记录列表
     * @param param
     * @return
     */
    @PostMapping("/queryChatRecordList")
    public   CommonResult<Page<Map<String,Object>>> queryChatRecordList(@RequestBody  Map<String,Object> param){
        return chatRelatedService.queryChatRecordList(param);
    }

    /**
     * 修改聊天记录读取状态
     * @param chatRecord
     * @return
     */
    @PostMapping("/updateReadStatus")
    public CommonResult<String> updateChatRecordReadStatus(@RequestBody ChatRecord chatRecord) {
        return chatRelatedService.updateChatRecordReadStatus(chatRecord);
    }

    /**
     * 添加用户与群聊的映射关系
     * @return
     */
    @PostMapping("/joinGroupChat")
    public  CommonResult<String> addUserGroupRelationship(@RequestBody  Map<String,Object> param){
        return chatRelatedService.addUserGroupRelationship(param,false);
    }


    /**
     * 查询聊天未读消息总数
     * @param userId
     * @return
     */
    @GetMapping("/queryChatUnreadQuantity/{userId}")
    public CommonResult<Map<String,Object>>  queryNumberOfChatUnreadMessages(@PathVariable("userId") String userId){
        return chatRelatedService.queryNumberOfChatUnreadMessages(userId);
    }

    /**
     * 推送聊天消息
     * @param message
     * @return
     */
    @PostMapping("/pushChatMessage")
    public CommonResult<Boolean> pushChatMessage(@RequestBody String message){
        return chatRelatedService.pushChatMessage(message);
    }
}
